//
//  UILabel+YJCSetting.m
//  MyDemos
//
//  Created by IOS3 on 2019/3/8.
//  Copyright © 2019 iMac. All rights reserved.
//

#import "UILabel+YJCSetting.h"

@implementation UILabel (YJCSetting)

/// set text
- (UILabel *(^)(NSString *text))setText {
    __weak typeof(self)weakSelf = self;
    return ^(NSString *text) {
        __strong typeof(weakSelf)strongSelf = weakSelf;
        strongSelf.text = text;
        return strongSelf;
    };
}

/// set textColor
- (UILabel *(^)(UIColor *color))setTextColor {
    __weak typeof(self)weakSelf = self;
    return ^(UIColor *color){
        __strong typeof(weakSelf)strongSelf = weakSelf;
        strongSelf.textColor = color;
        return strongSelf;
    };
}

/// set backgroundColor
- (UILabel *(^)(UIColor *color))setBGColor {
    __weak typeof(self)weakSelf = self;
    return ^(UIColor *color){
        __strong typeof(weakSelf)strongSelf = weakSelf;
        strongSelf.backgroundColor = color;
        return strongSelf;
    };
}

/// set system font size
- (UILabel *(^)(CGFloat size))setSysFont {
    __weak typeof(self)weakSelf = self;
    return ^(CGFloat size){
        __strong typeof(weakSelf)strongSelf = weakSelf;
        strongSelf.font = [UIFont systemFontOfSize:size];
        return strongSelf;
    };
}

/// set font size & fontName
- (UILabel *(^)(CGFloat size, NSString *name))setFontName {
    __weak typeof(self)weakSelf = self;
    return ^(CGFloat size, NSString *name){
        __strong typeof(weakSelf)strongSelf = weakSelf;
        strongSelf.font = [UIFont fontWithName:name size:size];
        return strongSelf;
    };
}

/// set attribute text
- (UILabel *(^)(NSAttributedString *attr))setAttrText {
    __weak typeof(self)weakSelf = self;
    return ^(NSAttributedString *attr){
        __strong typeof(weakSelf)strongSelf = weakSelf;
        strongSelf.attributedText = attr;
        return strongSelf;
    };
}

/// set frame
- (UILabel *(^)(CGRect frame))setFrame {
    __weak typeof(self)weakSelf = self;
    return ^(CGRect frame){
        __strong typeof(weakSelf)strongSelf = weakSelf;
        strongSelf.frame = frame;
        return strongSelf;
    };
}

/// set numberOfline
- (UILabel *(^)(NSInteger lineNum))setLineNum {
    __weak typeof(self)weakSelf = self;
    return ^(NSInteger lineNum){
        __strong typeof(weakSelf)strongSelf = weakSelf;
        strongSelf.numberOfLines = lineNum;
        return strongSelf;
    };
}

/// set textAlignment
- (UILabel *(^)(NSTextAlignment alignment))setAlignment {
    __weak typeof(self)weakSelf = self;
    return ^(NSTextAlignment alignment){
        __strong typeof(weakSelf)strongSelf = weakSelf;
        strongSelf.textAlignment = alignment;
        return strongSelf;
    };
}

/// set tag
- (UILabel *(^)(NSInteger tag))setTag {
    __weak typeof(self)weakSelf = self;
    return ^(NSInteger tag) {
        __strong typeof(weakSelf)strongSelf = weakSelf;
        strongSelf.tag = tag;
        return strongSelf;
    };
}

@end
